<template>
  <div>
    <el-form label-width="80px">
      <el-row>

        <el-col :span='8'>
          <el-form-item label="商品编号">
            <el-input v-model="form.id"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span='8'>
          <el-form-item label="商品名称">
            <el-input v-model="form.productTitle"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span='8'>
          <el-form-item label="生效时间">
            <el-date-picker
              v-model="time"
              type="datetimerange"
              placeholder="选择时间范围">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span='8'>
          <el-form-item label="状态">
            <el-select v-model="form.statusList" multiple placeholder="请选择活动状态">
              <el-option
                v-for='item in displayStatusArr'
                :label="item.label"
                :value="item.val"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-button type="primary" @click='submit'>搜索</el-button>
      </el-row>
    </el-form>
  </div>
</template>
<script>
  export default {
    data () {
      return {
        displayStatusArr: [
          {
            val: 'all',
            label: '全部'
          },
          {
            val: 1,
            label: '待生效'
          },
          {
            val: 2,
            label: '生效中'
          },
          {
            val: 3,
            label: '已失效'
          }
        ],
        activityTypeArr: [
          {
            val: '',
            label: '全部'
          },
          {
            val: 1,
            label: '立减活动'
          }
        ],
        time: [],
        form: {
          activityType: '',
          statusList: ['all'],
          endTime: '',
          startTime: '',
          tag: '',
          priceStrategyId: '',
          productId: '',
          productTitle: ''
        }
      }
    },
    watch: {
      'time': function () {
        if (this.time.length > 0) {
          this.form['startTime'] = new Date(this.time[0]).getTime()
          this.form['endTime'] = new Date(this.time[1]).getTime()
        }
      }
    },
    methods: {
      submit () {
        let params = {}
        for (let key in this.form) {
          if (this.form[key] !== '') {
            params[key] = this.form[key]
          }
        }
        if (this.form['statusList'].length > 0) {
          if (this.form['statusList'].indexOf('all') > -1) {
            params['statusList'] = [1, 2, 3]
          } else {
            params['statusList'] = this.form['statusList']
          }
        } else {
          params['statusList'] && delete params['statusList']
        }
        this.$emit('formSubmit', params)
      }
    }
  }
</script>
